<template>
  <a-card :title="'充绒单明细'">
    <div class="main">
      <div class="dtl">
        <a-row>
          <a-col :span="24">
            <a-descriptions bordered>
              <a-descriptions-item label="样衣号">
                {{ plushFillBillDtl.sampleCode }}
              </a-descriptions-item>
              <a-descriptions-item label="款号">
                {{ plushFillBillDtl.styleId }}
              </a-descriptions-item>
              <a-descriptions-item label="品名">
                {{ plushFillBillDtl.sampleName }}
              </a-descriptions-item>
              <a-descriptions-item label="创建时间">
                {{ plushFillBillDtl.createDate }}
              </a-descriptions-item>
              <a-descriptions-item label="业务员">
                {{ plushFillBillDtl.auderYwy }}
              </a-descriptions-item>
              <a-descriptions-item label="业务确认人">
                {{ plushFillBillDtl.auder }}
              </a-descriptions-item>
            </a-descriptions>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="24">
            <a-card v-for="(item, i) in cutpartList" :key="i" style="margin-top: 10px">
              <div>
                <a-row>
                  <a-col :span="3">
                    <a-row> 裁片名称 </a-row>
                    <a-row>
                      {{ item.cutName }}
                    </a-row>
                    <a-row> 裁片明细 </a-row>
                    <a-row v-for="(partItem, a) in item.part" :key="a">
                      {{ partItem.partName }}
                    </a-row>
                    <a-row> 单片合计 </a-row>
                  </a-col>
                  <a-col :span="21">
                    <a-row>
                      <div style="display: flex">
                        <div :style="{ width: `${100 / sizeList.length}%` }">片数</div>
                        <div :style="{ width: `${100 / sizeList.length}%` }">备注</div>
                      </div>
                    </a-row>
                    <a-row>
                      <div style="display: flex">
                        <div :style="{ width: `${100 / sizeList.length}%` }">
                          {{ item.pieces }}
                        </div>
                        <div :style="{ width: `${100 / sizeList.length}%` }">
                          {{ item.remark }}
                        </div>
                      </div>
                    </a-row>
                    <a-row>
                      <div style="display: flex">
                        <div v-for="(sizeItem, b) in sizeList" :key="b" :style="{ width: `${100 / sizeList.length}%` }">
                          {{ sizeItem.model }}
                        </div>
                      </div>
                    </a-row>
                    <a-row>
                      <div style="display: flex">
                        <div v-for="(sizeItem, b) in sizeList" :key="b" :style="{ width: `${100 / sizeList.length}%` }">
                          <div v-for="(partItem, a) in item.part" :key="a" style="display: flex">
                            <div v-for="(numItem, a) in partItem.partNum" :key="a" style="display: flex">
                              <div v-if="sizeItem.model == numItem.sizeid">
                                {{ numItem.consume }}
                              </div>
                            </div>
                          </div>
                          <div v-for="totItem in item.total" :key="totItem.sizeid">
                            <div v-if="sizeItem.model==totItem.sizeid">
                              {{ totItem.consume }}
                            </div>
                          </div>
                        </div>
                      </div>
                    </a-row>
                  </a-col>
                </a-row>
              </div>
            </a-card>
          </a-col>
        </a-row>
      </div>
      <div class="statsc"></div>
    </div>
  </a-card>
</template>

<script>
export default {
  data() {
    return {
      plushFillBillDtl: {},
      cutpartList: [], //裁片列表
      sizeList: [], //尺码档案
      cutpartDtl: [], //裁片详情
      cutpartUseNum: [], //裁片明细用量
      cutpartTotal: [], //裁片合计数量
      sampleCode: ''
    }
  },
  computed: {
    userInfo() {
      return this.$store.getters.userInfo || null
    }
  },
  mounted() {
    this.getSizeData()
  },
  created() {
    this.sampleCode = this.$route.query.sampleCode
    if (this.sampleCode) {
      this.$nextTick(() => {
        this.getPlushFillDtl()
        this.getCutpartList()
        // console.log(this.cutpartList)
      })
    }
  },
  methods: {
    getPlushFillDtl() {
      const params = {
        sampleCode: this.sampleCode
      }
      try {
        const res = {
          code: 200,
          success: true,
          data: {
            sampleCode: 'T08N30',
            styleId: '1M9C11951',
            sampleName: '',
            season: '2023秋冬',
            createDate: '2023/4/25',
            auderDate: '2023/4/25',
            auder: '李贝'
          },
          msg: '操作成功!'
        }
        if (res.code == 200) {
          this.plushFillBillDtl = res.data
        } else {
          if (res.msg) {
            this.$message.warning(res.msg)
          } else {
            this.$message.warning('获取充绒单详情失败!')
          }
        }
      } catch (error) {
        this.$message.warning('获取充绒单详情失败!')
      }
    },
    //获取裁片列表
    getCutpartList() {
      const params = {
        sampleCode: this.sampleCode
      }
      try {
        const res = {
          code: 200,
          success: true,
          data: {
            records: [
              {
                cutName: '前片',
                pieces: 2,
                remark: '',
                part: [
                  {
                    partName: '[前片-1]',
                    partNum: [
                      {
                        sizeid: '100',
                        consume: 1.18
                      },
                      {
                        sizeid: '110',
                        consume: 1.51
                      },
                      {
                        sizeid: '120',
                        consume: 1.85
                      },
                      {
                        sizeid: '130',
                        consume: 2.18
                      },
                      {
                        sizeid: '140',
                        consume: 2.51
                      },
                      {
                        sizeid: '150',
                        consume: 2.84
                      },
                      {
                        sizeid: '160',
                        consume: 3.17
                      }
                    ]
                  },
                  {
                    partName: '[前片-2]',
                    partNum: [
                      {
                        sizeid: '100',
                        consume: 1.93
                      },
                      {
                        sizeid: '110',
                        consume: 2.37
                      },
                      {
                        sizeid: '120',
                        consume: 2.81
                      },
                      {
                        sizeid: '130',
                        consume: 3.26
                      },
                      {
                        sizeid: '140',
                        consume: 3.7
                      },
                      {
                        sizeid: '150',
                        consume: 4.14
                      },
                      {
                        sizeid: '160',
                        consume: 4.59
                      }
                    ]
                  },
                  {
                    partName: '[前片-3]',
                    partNum: [
                      {
                        sizeid: '100',
                        consume: 2.47
                      },
                      {
                        sizeid: '110',
                        consume: 2.92
                      },
                      {
                        sizeid: '120',
                        consume: 3.38
                      },
                      {
                        sizeid: '130',
                        consume: 3.84
                      },
                      {
                        sizeid: '140',
                        consume: 4.3
                      },
                      {
                        sizeid: '150',
                        consume: 4.76
                      },
                      {
                        sizeid: '160',
                        consume: 5.22
                      }
                    ]
                  },
                  {
                    partName: '[前片-4]',
                    partNum: [
                      {
                        sizeid: '100',
                        consume: 2.53
                      },
                      {
                        sizeid: '110',
                        consume: 3.01
                      },
                      {
                        sizeid: '120',
                        consume: 3.49
                      },
                      {
                        sizeid: '130',
                        consume: 3.96
                      },
                      {
                        sizeid: '140',
                        consume: 4.44
                      },
                      {
                        sizeid: '150',
                        consume: 4.92
                      },
                      {
                        sizeid: '160',
                        consume: 5.39
                      }
                    ]
                  },
                  {
                    partName: '[前片-5]',
                    partNum: [
                      {
                        sizeid: '100',
                        consume: 2.75
                      },
                      {
                        sizeid: '110',
                        consume: 3.26
                      },
                      {
                        sizeid: '120',
                        consume: 3.77
                      },
                      {
                        sizeid: '130',
                        consume: 4.29
                      },
                      {
                        sizeid: '140',
                        consume: 4.8
                      },
                      {
                        sizeid: '150',
                        consume: 5.31
                      },
                      {
                        sizeid: '160',
                        consume: 5.83
                      }
                    ]
                  }
                ]
              },
              {
                cutName: '后片',
                pieces: 1,
                remark: '对称',
                part: [
                  {
                    partName: '[后片-1]',
                    partNum: [
                      {
                        sizeid: '100',
                        consume: 2.98
                      },
                      {
                        sizeid: '110',
                        consume: 3.69
                      },
                      {
                        sizeid: '120',
                        consume: 4.41
                      },
                      {
                        sizeid: '130',
                        consume: 5.12
                      },
                      {
                        sizeid: '140',
                        consume: 5.84
                      },
                      {
                        sizeid: '150',
                        consume: 6.55
                      },
                      {
                        sizeid: '160',
                        consume: 7.27
                      }
                    ]
                  },
                  {
                    partName: '[后片-2]',
                    partNum: [
                      {
                        sizeid: '100',
                        consume: 3.75
                      },
                      {
                        sizeid: '110',
                        consume: 4.68
                      },
                      {
                        sizeid: '120',
                        consume: 5.62
                      },
                      {
                        sizeid: '130',
                        consume: 6.55
                      },
                      {
                        sizeid: '140',
                        consume: 7.48
                      },
                      {
                        sizeid: '150',
                        consume: 8.42
                      },
                      {
                        sizeid: '160',
                        consume: 9.35
                      }
                    ]
                  },
                  {
                    partName: '[后片-3]',
                    partNum: [
                      {
                        sizeid: '100',
                        consume: 5.05
                      },
                      {
                        sizeid: '110',
                        consume: 5.96
                      },
                      {
                        sizeid: '120',
                        consume: 6.87
                      },
                      {
                        sizeid: '130',
                        consume: 7.78
                      },
                      {
                        sizeid: '140',
                        consume: 8.69
                      },
                      {
                        sizeid: '150',
                        consume: 9.6
                      },
                      {
                        sizeid: '160',
                        consume: 10.51
                      }
                    ]
                  },
                  {
                    partName: '[后片-4]',
                    partNum: [
                      {
                        sizeid: '100',
                        consume: 5.07
                      },
                      {
                        sizeid: '110',
                        consume: 6.02
                      },
                      {
                        sizeid: '120',
                        consume: 6.97
                      },
                      {
                        sizeid: '130',
                        consume: 7.92
                      },
                      {
                        sizeid: '140',
                        consume: 8.87
                      },
                      {
                        sizeid: '150',
                        consume: 9.82
                      },
                      {
                        sizeid: '160',
                        consume: 10.77
                      }
                    ]
                  },
                  {
                    partName: '[后片-5]',
                    partNum: [
                      {
                        sizeid: '100',
                        consume: 5.24
                      },
                      {
                        sizeid: '110',
                        consume: 6.19
                      },
                      {
                        sizeid: '120',
                        consume: 7.14
                      },
                      {
                        sizeid: '130',
                        consume: 8.09
                      },
                      {
                        sizeid: '140',
                        consume: 9.04
                      },
                      {
                        sizeid: '150',
                        consume: 9.99
                      },
                      {
                        sizeid: '160',
                        consume: 10.94
                      }
                    ]
                  }
                ]
              }
            ]
          },
          msg: '操作成功!'
        }
        this.cutpartList = res.data.records

        this.cutpartList.forEach((item) => {
          this.$set(item,"total",[])
          item.part.forEach((x) => {
            x.partNum.forEach((y) => {
              let idx = item.total.findIndex( itemx => itemx.sizeid == y.sizeid)
              if(idx == -1){
                item.total.push({ sizeid: y.sizeid, consume: Number(parseFloat(y.consume).toFixed(2)) })
              }else{
                item.total[idx].consume += Number(parseFloat(y.consume).toFixed(2))
              }
            })
          })
          item.total.forEach((k) => {
            k.consume = Number(parseFloat(k.consume).toFixed(2))
          })
        })
        console.log(this.cutpartList)
      } catch (error) {
        console.log(error)
        this.$message.warning('获取裁片信息失败!')
      }
    },

    //获取尺码档案
    getSizeData() {
      const params = {
        sampleCode: this.sampleCode
      }
      try {
        const res = {
          code: 200,
          success: true,
          data: [
            {
              stypartid: 1,
              designid: 'T08N30',
              styleId: '1M9C11951',
              model: '100'
            },
            {
              stypartid: 2,
              designid: 'T08N30',
              styleId: '1M9C11951',
              model: '110'
            },
            {
              stypartid: 3,
              designid: 'T08N30',
              styleId: '1M9C11951',
              model: '120'
            },
            {
              stypartid: 4,
              designid: 'T08N30',
              styleId: '1M9C11951',
              model: '130'
            },
            {
              stypartid: 5,
              designid: 'T08N30',
              styleId: '1M9C11951',
              model: '140'
            },
            {
              stypartid: 6,
              designid: 'T08N30',
              styleId: '1M9C11951',
              model: '150'
            },
            {
              stypartid: 7,
              designid: 'T08N30',
              styleId: '1M9C11951',
              model: '160'
            }
          ],
          msg: '操作成功!'
        }
        if (res.code == 200) {
          this.sizeList = res.data
        } else {
          if (res.msg) {
            this.$message.warning(res.msg)
          } else {
            this.$message.warning('获取尺码档案失败!')
          }
        }
      } catch (error) {
        this.$message.warning('获取尺码档案失败!')
      }
    }
  }
}
</script>
